<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

    <title>地址管理</title>

    <link href="__PUBLIC__/AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css">
    <link href="__PUBLIC__/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css">

    <link href="__PUBLIC__/css/personal.css" rel="stylesheet" type="text/css">
    <link href="__PUBLIC__/css/addstyle.css" rel="stylesheet" type="text/css">
    <script src="__PUBLIC__/AmazeUI-2.4.2/assets/js/jquery.min.js" type="text/javascript"></script>
    <script src="__PUBLIC__/AmazeUI-2.4.2/assets/js/amazeui.js"></script>
    <script src="__PUBLIC__/js/global.js"></script>
    <script src="__PUBLIC__/layer/layer.js"></script>
    <style>
        .addressmone{ width:100%; overflow:hidden; background:#fff}
        .addressmone ul{ width:95%; overflow:hidden; margin:auto}
        .addressmone ul li{ width:100%; overflow:hidden; border-bottom:1px solid #CCC;}
        .addressmone ul li span{ display:block; float:left; width:30%; font-size:14px; line-height:45px; color:#666;}
        .addressmone ul li input{ display:block; float:left; width:60%; background:none; border:0px; font-size:16px; color:#333; line-height:45px;}
        .addressmone ul li select{ display:block; float:left;background:none; height:45px; border:0px; font-size:16px; color:#333; line-height:45px; padding-right:10px;-webkit-appearance: none; -webkit-box-flex: 1; -webkit-flex: 1; flex: 1; border-radius: 0; -webkit-rtl-ordering: logical; -webkit-user-select: text;}
    </style>
</head>


<body>

<div class="center">
    <div class="col-main">
        <div class="main-wrap">

            <div class="user-address">
                <!--标题 -->

                <ul class="am-avg-sm-1 am-avg-md-3 am-thumbnails">
                    <volist name="addressList" id="vo">
                        <eq name="vo.is_default" value="1">
                        <li class="user-addresslist defaultAddr" id="{$vo.address_id}">
                            <else/>
                            <li class="user-addresslist" id="{$vo.address_id}">
                        </eq>
                        <span onclick="setDefault({$vo.address_id})" class="new-option-r"><i class="am-icon-check-circle"></i>默认地址</span>

                        <p class="new-tit new-p-re">
                            <span class="new-txt">{$vo.consignee}</span>
                            <span class="new-txt-rd2">{$vo.mobile}</span>
                        </p>
                        <div class="new-mu_l2a new-p-re">
                            <p class="new-mu_l2cw">
                                <span class="title">地址：</span>
                                <span class="province"></span>
                                <span class="city"></span>
                                <span class="dist"></span>
                                <span class="street">{$vo.area} {$vo.address}</span></p>
                        </div>
                        <div class="new-addr-btn">
                            <a href="#" onclick="editAddress({$vo.address_id})"><i class="am-icon-edit"></i>编辑</a>
                            <span class="new-addr-bar">|</span>
                            <a href="javascript:void(0);" onclick="delClick({$vo.address_id});"><i class="am-icon-trash"></i>删除</a>
                        </div>
                    </li>
                    </volist>
                    <input type="hidden" id="address_count" value="{$count}">
                </ul>
                <div class="clear"></div>
                <!--<a class="new-abtn-type" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0}">添加新地址</a>-->
                <a class="new-abtn-type" onclick="addAddress()">添加新地址</a>

                <!--例子-->
                <div class="am-modal am-modal-no-btn" id="doc-modal-1" style="overflow: auto;">

                    <div class="add-dress">

                        <!--标题 -->
                        <div class="am-cf am-padding">
                            <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> /
                                <small>Add&nbsp;address</small>
                            </div>
                        </div>
                        <hr/>

                        <div class="am-u-md-12 am-u-lg-8" style="margin-top: 20px;width: 98%">
                        </div>

                    </div>

                </div>

            </div>

            <script type="text/javascript">
                $(document).ready(function () {
                    $(".new-option-r").click(function () {
                        $(this).parent('.user-addresslist').addClass("defaultAddr").siblings().removeClass("defaultAddr");
                    });

                    var $ww = $(window).width();
                    if ($ww > 640) {
                        $("#doc-modal-1").removeClass("am-modal am-modal-no-btn")
                    }
                    var count = $('#address_count').val();
                    if(count == '0'){
                        modalInfo('您还没有添加任何地址信息！');
                    }

                });


                function editAddress(addressId){


                    window.location.href = '__URL__/addressUI?address_id=' + addressId;

                }

                function addAddress(){

                    window.location.href = '__URL__/addressUI';

                }

                function submit_address(){

                    if($("[name=consignee]").val() == '') {
                        modalInfo('联系人不能为空');
                        return ;
                    }

                    if($("[name=mobile]").val() == '') {
                        modalInfo('手机号码不能为空');
                        return ;
                    }

                    if($("[name=address]").val() == '') {
                        modalInfo('详细地址不能为空');
                        return ;
                    }

                    if($("[name=province]").val() <= 0) {
                        modalInfo('省份不能为空');
                        return ;
                    }

                    if($("[name=province]").val() <= 0) {
                        modalInfo('省份不能为空');
                        return ;
                    }
                    if($("[name=city]").val() <= 0) {
                        modalInfo('城市不能为空');
                        return ;
                    }
                    if($("[name=district]").val() <= 0) {
                        modalInfo('区域不能为空');
                        return ;
                    }

                    var formData = new FormData(document.getElementById('addEditAddress'));
                    $.ajax({
                        type:"post",
                        url:"__URL__/addEditAddress",
                        data : formData,
                        processData: false,
                        contentType: false,
                        error:function (data) {
                            console.info(data);
                            modalInfo("服务器繁忙");
                        },
                        success:function (data) {
                            console.info(data);
                            modalInfo(data.msg);
                            if(data.status > 0)
                            {
                                location.reload()
                            }

                        }

                    })



                }


                function modalInfo(info){
                    layer.msg(info);
//                    layer.open({
//                        content: info
//                        ,skin: 'msg'
//                        ,time: 1000 //2秒后自动关闭
//                    });

                }

                function setDefault(id){
                    $.ajax({

                        type:"post",
                        url:"__URL__/setDefaultAddress",
                        data:{

                            id:id
                        },
                        error:function (data) {
                            console.info(data);
                            modalInfo('服务器繁忙');
                        },
                        success:function (data) {
                            console.info(data);
//                            modalInfo(data.msg);



                        }




                    });



                }


                function delClick(id){

                    $.ajax({
                        type:"get",
                        url:"__URL__/delAddress?id=" + id,
                        error:function (data) {
                            console.info(data);
                        },
                        success:function (data) {
                            console.info(data);
                            $('#'+id).remove();
                        }


                    });


                }

            </script>


        </div>


    </div>


</div>

</body>

</html>